<?php

include_once($cfgPaths['lib'].'cms/type/cmsEditType.o.inc.php');

class cmsEditIncDocType extends cmsEditType {

 function registerFields () {
   $map[] = $this->name.'tpl';
   $map[] = $this->name.'src';
   $this->map = &$map;
 }

 function render_html () {
  global $cfgPaths,$cfgDeveloperMode,$env;
  $tpl = $this->getValue($this->name.'tpl');
  $html  = '<div class="xicstypeplugin">'."\n";
  $html .= '    <h3>'.$this->descr.':</h3>'.$this->showFields()."\n";
  $html .= '<table border="0">'."\n";
  $html .= '  <tr>'."\n";
  $html .= '    <td>'."\n";
  $html .= '    Template:</td>'."\n";
  $html .= '    <td>'."\n";
  $html .= '<select name="'.$this->name.'tpl" tabindex="'.$this->sender->getNextTabindex($this->name.'tpl').'">'."\n";
  if ($cfgDeveloperMode)
  {
    $dir = $cfgPaths['template'].'cms/inc/';
    if (file_exists($dir)){
        $dh = opendir($dir);
        rewinddir($dh);
        while($file = readdir($dh))
        {
            if (!is_dir($dir.$file) && !preg_match('/serialized$/',$file))
            {
                $dirarr[] = $file;
            }
        }
        sort($dirarr);
        for ($i=0;$i<count($dirarr);$i++) 
        {
            $html .= '<option';
            if ($dirarr[$i]==$tpl)
                $html .= " selected";
            $html .= '>'.$dirarr[$i].'</option>';
        }
    }
  }
  else
  {
        $els = $GLOBALS['tdba']->getBySiteAndType($env->getSession('s_currentSite'),'inc');
        for ($i=0;$i<count($els);$i++)
        {
            $html .= '<option';
            if ($tpl==$els[$i]['filename']) 
                $html .= " selected";
            $html .= ' value="'.urlencode($els[$i]['filename']).'">'.$els[$i]['name'].'</option>';
        }
  }
  $html .= '        </select>'."\n";
  $html .= '    </td>'."\n";
  $html .= '  </tr>'."\n";
  $html .= '  <tr>'."\n";
  $html .= '    <td>'."\n";
  $html .= '    Dokument:</td>'."\n";
  $html .= '    <td>'."\n";
  $html .= '      <input tabindex="'.$this->sender->getNextTabindex($this->name.'src').'" name="'.$this->name.'src" value="'.htmlspecialchars($this->getValue($this->name.'src')).'" size="45" maxlength="255"> <a style="vertical-align:top" href="javascript:void(0);" onClick="fenster=window.open(\'cmsEditlink/OpenDialogFrame.php?caller='.$this->name.'src&mode=src\',\'LinkOpenDialog\',\'menubar=no,status=no,width=300,height=300\');"><img src="' . 
  base_ApplicationContext::getInstance()->mediaPath()->main(). 'cms/folder_page.png" border="0"/></a>';
  if (preg_match('/^pageid:(.*)$/',$this->getValue($this->name.'src'),$matches))
  {
        $html .= '<br/><b>Dokument:</b> '.$GLOBALS['docs']->extractPathStr($matches[1],'name','/');
  }
  $html .= '<td>'."\n";
  $html .= '  </tr>'."\n";
  $html .= '</table>'."\n";
  $html  .= '</div><!-- / type selection -->'."\n";
  return $html;
 }

 function render_javascript () {
 }

}


?>
